#ifndef GENIE_FET
#define GENIE_FET

#include "common.h"

typedef union
{
   UINT16  word;
   struct
   {
      UINT16  forward: 1;
      UINT16  reverse: 1;
      UINT16  up: 1;
      UINT16  down: 1;
      UINT16  right: 1;
      UINT16  left: 1;
      UINT16  brakes: 1;
      UINT16  mce: 1;
      UINT16  horn: 1;
      UINT16  hourmeter: 1;
      UINT16  spare: 1;
      UINT16  alarm: 1;
      UINT16  selA: 1;
      UINT16  selB: 1;
      UINT16  selC: 1;
      UINT16  selD: 1;
   } fet;
} Fet_t;

//Rick@20151102 the first bit selD and the data length is 16 bits
#define FET_BIT_OUT(xYz) xYz ## .fet.selD
#define FET_BITS   16
#define FETS    Fets.word

extern Fet_t Fets;

#define FET_ON 1
#define FET_OFF 0

//Rick@20151102  This is the bit information MCU send to serial/parallel device
//On schematic
#define FET_FORWARD 0x1     //FWD/REV_1
#define FET_REVERSE 0x2     //FWD/REV_2
#define FET_UP      0x4     //RAISE
#define FET_DOWN    0x8     //LOWER

#define FET_RIGHT   0x10    //STEER_RIGHT
#define FET_LEFT    0x20    //STEER_LEFT
#define FET_BRAKES  0x40    //BEACON
#define FET_MCE     0x80    //MOTOR_CNTL_ENABLE

#define FET_HORN     0x100  //HORN
#define FET_PARALLEL 0x200  //HOUR_METER
#define FET_MCE2   0x200
#define FET_SPARE    0x400  //LED_DRIVE
#define FET_BEACON   0x400
#define FET_ALARM    0x800  //2A/OUTPUT

#define FET_SELA     0x1000      //it is signal to FET drivers
#define FET_SELB     0x2000      //it is signal to FET drivers
#define FET_SELC     0x4000      //it is signal to FET drivers
#define FET_SELD     0x8000      //it is signal to FET drivers

//#define MODE_FETS ( FET_FORWARD | FET_REVERSE | FET_UP | FET_DOWN)

#define FET_COILS ( FET_FORWARD \
                    | FET_REVERSE \
                    | FET_UP \
                    | FET_DOWN \
                    | FET_RIGHT \
                    | FET_LEFT \
                    | FET_BEACON \
                    | FET_MCE \
                    | FET_PARALLEL )

#define SOLENOID_SHORT_CURRENT   1020//870 // increase threshold from 670 for 12 volt coils
#define SOLENOID_OPEN_CURRENT    30  //0.13A

extern unsigned int DriveCurrent;

extern void FET_Update(void);
extern void FET_Init(void);
extern void FET_Check(void);
extern void FET_Setup(void);
extern void vCheckDualOpenCircuit(void);

#endif  //GENIE_FET
